import type { KpcodeBarcodeScanEntity } from '@/types/code'
import type { PageResult } from '@/types/global'
import type { CashApproveItem, LoginResult, UserJackItem, userItem } from '@/types/member'
import { http } from '@/utils/http'

type LoginParams = {
  grant_type?: string
  mobile?: string
  code: string
}

type PhoneResult = {
  phoneNumber: string
}
/**
 * 小程序登录
 * @param data 请求参数
 */
export const postLoginWxMinAPI = (code: string, phone?: string) => {
  return http<LoginResult>({
    method: 'POST',
    url: `/admin/appletApi/loginAppleByCode?code=${code}&phone=${phone}`,
  })
}

/**
 * 获取手机号
 * @param data 请求参数
 */
export const postPhoneAPI = (code: string) => {
  return http<PhoneResult>({
    method: 'POST',
    url: `/admin/appletApi/getPhoneByCode?code=${code}`,
  })
}

// 使用userId查询用户信息
export const getUserInfoByIdAPI = (userId: string) => {
  return http<userItem>({
    method: 'GET',
    url: `/admin/appuser/details/${userId}`
  })
}

// 修改用户信息
export const putUserInfoAPI = (data: userItem) => {
  return http({
    method: 'PUT',
    url: '/admin/appuser',
    data,
  })
}

// 用户实名认证
export const postUserRealNameAPI = (data: userItem) => {
  return http({
    method: 'POST',
    url: '/admin/appletApi/realName',
    data,
  })
}

/**
 *
 * @param data 获取微信用户列表
 */
export const getWXUserListAPI = (username: string) => {
  return http<PageResult<userItem>>({
    method: 'GET',
    url: `/admin/businessApi/getAppUserPage?username=${username}`,
  })
}

// 用户扫码列表
export const getUserScanListAPI = (id: string) => {
  return http<KpcodeBarcodeScanEntity[]>({
    method: 'GET',
    url: `/admin/consumer/barcodeScanList?appUserId=${id}`,
  })
}

// 用户抽奖列表
export const getUserJackListAPI = (id: string) => {
  return http<UserJackItem[]>({
    method: 'GET',
    url: `/admin/consumer/userJackList?appUserId=${id}`,
  })
}

// 用户提现列表
export const getUserCashApproveListAPI = (id: string) => {
  return http<PageResult<UserJackItem[]>>({
    method: 'GET',
    url: `/admin/consumer/userCashApproveList?appUserId=${id}`,
  })
}

// 用户待提取金额
export const getUserCashAmountAPI = (id: string) => {
  return http({
    method: 'GET',
    url: `/admin/consumer/appUserAmount?appUserId=${id}`,
  })
}

// 用户扫码列表
export const getUserBarcodeScanListAPI = (id: string) => {
  return http<UserJackItem[]>({
    method: 'GET',
    url: `/admin/consumer/barcodeScanList?appUserId=${id}`,
  })
}

// 用户提现
export const postUserCashApproveAPI = (userId: string, cashPrice: string, openId: string) => {
  return http({
    method: 'POST',
    url: `/admin/consumer/userCashApprove?userId=${userId}&cashPrice=${cashPrice}&openId=${openId}`,
  })
}
// 用户提现列表
export const postUserCashApproveListAPI = (appUserId: string) => {
  return http<CashApproveItem[]>({
    method: 'GET',
    url: `/admin/consumer/userCashApproveList?appUserId=${appUserId}`,
  })
}

// 扫码抽奖
export const postUserScanCodeAPT = (data: {scanCode: string, userId: string}) => {
  return http({
    method: 'POST',
    url: '/admin/consumer/userScanCode',
    data,
  })
}
type cashPrizeRequest = { id?:string, winningSpeech?: string, winningImages?: string }
// 用户提交获奖感言
export const postUserCashPrizeAPI = (data: cashPrizeRequest) => {
  return http({
    method:'POST',
    url: '/admin/consumer/userCashPrize',
    data,
  })
}

// 获取配送数量
export const getDeliveryNoAPI = (id: string) => {
  return http({
    method: 'GET',
    url: '/admin/barcodeApi/deliveryNo?deliveryId=' + id,
  })
}
